import { UserHttp } from '../api/user.js'

const userModel = new UserHttp

// 检测登录状态，返回 true / false
async function checkHasLogined() {
  const token = wx.getStorageSync('token')
  if (!token) {
    return false
  }
  wx.checkSession({
    fail() {
      return false
    }
  })
  const checkTokenRes = await userModel.getUserInfo()
  if (checkTokenRes.code === 2007) {
    wx.removeStorageSync('token')
    return false
  }
  return true
}

module.exports = {
  checkHasLogined: checkHasLogined
}